package kafkaStudy;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.kafka.listener.MessageListener;

/** 
* @author 朱宏亮
* @version 创建时间：2017年12月17日 下午2:15:26 
* 类说明 kafka_2.11-1.0.0整合spring4.3.13 自动监听
*/
public class KafkaConListen implements MessageListener<Integer, String>{

	public void onMessage(ConsumerRecord<Integer, String> record) {
		
		System.out.println("=============Listener开始消费=============");
        String topic = record.topic();
        Integer key = record.key();
        String value = record.value();
        long offset = record.offset();
        int partition = record.partition();
        System.out.println("-------------topic:"+topic);
        System.out.println("-------------value:"+value);
        System.out.println("-------------key:"+key);
        System.out.println("-------------offset:"+offset);
        System.out.println("-------------partition:"+partition);
        System.out.println("~~~~~~~~~~~~~Listener消费结束~~~~~~~~~~~~~");
	}
	
	/*@SuppressWarnings({  "resource", "unused" })
	public static void main(String[] args){
		ApplicationContext factory = new ClassPathXmlApplicationContext("classpath:kafkaConsumerListen.xml");

	}*/
	
	
}
